//
//  LookViewCell.m
//  滴滴快拍
//
//  Created by dllo on 16/5/30.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LookViewCell.h"
#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height


@implementation LookViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)setModel:(AGLChannel *)model {
    if (_model != model) {
        _model = model;
    }
    [self createData];
    
}

- (void)createData {
    
    self.titleLabel.text   = self.model.ft;
    //    cell.contentLabel.text = info.streambase;
    [self.preViewImageView setImageWithURL:[NSURL URLWithString:self.model.previewStr] placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
    self.timeLabel.text    = self.model.finishTimeNice;

    
}

- (void)createView {
    _titleLabel                 = [[BaseLabel alloc] init];
    _titleLabel.backgroundColor = [UIColor clearColor];
    _titleLabel.font            = [UIFont boldSystemFontOfSize:16];
    [self.contentView addSubview:_titleLabel];

    _timeLabel                 = [[BaseLabel alloc] init];
    _timeLabel.backgroundColor = [UIColor clearColor];
    _timeLabel.font            = [UIFont systemFontOfSize:12];
    //        _timeLabel.textColor       = RGB(159, 159, 159);
    _timeLabel.numberOfLines   = 0;
    [self.contentView addSubview:_timeLabel];

    _preViewImageView                 = [[BaseImageView alloc] init];
    _preViewImageView.backgroundColor = [UIColor clearColor];
    //        _contentLabel.font            = [UIFont systemFontOfSize:14];
    //        _contentLabel.textColor       = RGB(159, 159, 159);
    [self.contentView addSubview:_preViewImageView];
    
    //长按手势
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longAction:)];
    [self addGestureRecognizer:longPress];

    
}


#pragma mark - 长按手势 删除 // 安国立到此一游
- (void)longAction:(UILongPressGestureRecognizer *)press{
    //如果长按开始
    if (press.state == UIGestureRecognizerStateBegan) {
        //        NSLog(@"长按动作触发!%@", self.model.title);
        
        
        [self.delegate deleteCellWithObjectId:self.model.objectId ft:self.model.ft  index:self.index];
        
        
    }
    
}


- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.titleLabel.frame   = CGRectMake(12, 10, WIDTH -24, 16);
    self.timeLabel.frame    = CGRectMake(12, HEIGHT - 30, 120, 13);
    self.preViewImageView.frame = CGRectMake(12, 30, WIDTH - 24, HEIGHT - 75);

    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
